//
//  WFMainTableViewController.swift
//  SwiftWeiBo
//
//  Created by 刘文锋 on 15/11/22.
//  Copyright © 2015年 刘文锋. All rights reserved.
//

import UIKit

class WFMainTableViewController: UITabBarController
{

    override func viewDidLoad()
    {
        super.viewDidLoad()
        
        tabBar.tintColor = UIColor.orangeColor()
  
        
        //首页
        let homeVC = WFHomeTableViewController()
        addChildViewController(homeVC, title: "首页", iconImage: "tabbar_home")
        
        //消息
        let messagerVC = WFMessageTableViewController()
        addChildViewController(messagerVC, title: "消息", iconImage: "tabbar_message_center")
        
        //占为
        addChildViewController(UIViewController())
        
        //发现
        let discoverVC = WFDiscoverTableViewController()
        addChildViewController(discoverVC, title: "发现", iconImage: "tabbar_discover")
        
        //我
        let profileVC = WFProfileTableViewController()
        addChildViewController(profileVC, title: "我", iconImage: "tabbar_profile")
       
    }
    /**
    自定义添加tabbar子控制器
    
    - parameter controller: 子控制器
    - parameter title:      子控制器的标题
    - parameter imageName:  子控制器的图片名称
    */
    // private 表示只有本类或当前文件的其他类可以访问
    private func addChildViewController(VC:UIViewController,title:String,iconImage:String)
    {
        VC.title = title
        VC.tabBarItem.image = UIImage(named: iconImage)
        addChildViewController(UINavigationController(rootViewController: VC))
       
    }
  //        // 设置撰写按钮的frame
    override func viewWillAppear(animated: Bool)
    {
        super.viewWillAppear(animated)
        // 设置撰写按钮的frame
        let width = tabBar.bounds.size.width/5
        let frame = CGRect(x: 2 * width - 5, y: 0, width: width + 10, height: tabBar.bounds.size.height)
        composeButton.frame = frame
        
    }
    // 懒加载
    /// 撰写按钮
    lazy var composeButton:UIButton =
    {
        let button = UIButton()
        // 设置参数
        // 设置按钮背景图片
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
         // 设置按钮图片
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        // 添加到tabbar里面
        self.tabBar.addSubview(button)
         // 添加点击事件
        button.addTarget(self, action: "composeClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        return button
        
    }()
    func composeClick()
    {
        print("出来了")
    }
}
